//
//  ZYBaseViewController.swift
//  weibo007
//
//  Created by 陈宗毅 on 15/12/15.
//  Copyright © 2015年 czy. All rights reserved.
//

import UIKit

class ZYBaseViewController: UITableViewController,ZYVistorViewDelegate {
    
    var userLogin = ZYUserAccount.userLogin
    
    override func loadView() {
        userLogin ? super.loadView(): setupVistorView()
    }
    /**
    设置访客视图
    */
    func setupVistorView()
    {
        //设置一个view
        view = visitorView
        
        visitorView.delegate = self
        
        //设置导航栏按钮
        //左边
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginClick")
        
        //判断当前是哪个控制器
        if self is ZYHomeViewController{
            
            //显示动画
            visitorView.startRotationAnition()
            //程序对到后台进入前台都会发送通知
            //注册通知
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackgroun", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            
        }else if self is ZYMessageViewController
        {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is ZYDiscoveryViewController
        {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is ZYProfileViewController
        {
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
    }
    
    deinit
    {
        //首页移除通知
        if self is ZYHomeViewController {
            NSNotificationCenter.defaultCenter().removeObserver(self)
        }
    }
    
    func visitorViewLoginClick() {
//        print(__FUNCTION__)
        let oauthVC = ZYOatuchViewController()
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
    
    func visitorViewRegisterClick() {
        print(__FUNCTION__)
    }
    
    //MARK:- 通知
    func didEnterBackgroud()
    {
        //停止转轮旋转
        print(__FUNCTION__)
        visitorView.pauseAnimation()
    }
    
    func didBecomeActive()
    {
        print(__FUNCTION__)
        visitorView.resumeAnimation()
    }
    
    
    
    //懒加载 访客视图
    lazy  var visitorView :ZYVistorView = ZYVistorView()
    
}
